import Vue from 'vue'
import VueRouter from 'vue-router'
import {setUser,getUser,removeUser} from '@/api/session';
Vue.use(VueRouter)

const routes = [
  {
	  path: '/index',//首页
	  name: 'index',
	  component: () => import('@/views/Index')
   },
   {
	  path: '/register',//注册
	  name: 'register',
	  component: () => import('@/views/Register')
   },
   {
	  path: '/login',//登录
	  name: 'login',
	  component: () => import('@/views/Login')
   },
   {
	  path: '/forgetPass',//忘记密码
	  name: 'forgetPass',
	  component: () => import('@/views/ForgetPass')
   },
   {
	  path: '/chartList',//讯息
	  name: 'chartList',
	  component: () => import('@/views/tab/ChartList')
   },
   {
	  path: '/friendCircle',//动态
	  name: 'friendCircle',
	  component: () => import('@/views/tab/FriendCircle')
   },
   {
	  path: '/chatIndex',//聊天界面
	  name: 'chatIndex',
	  component: () => import('@/views/chat/chatIndex')
   },
   {
	  path: '/',//遇见
	  name: '/meet',
	  component: () => import('@/views/tab/Meet')
   },
   {
	  path: '/sendGift',//遇见->用户主页->礼物
	  name: 'sendGift',
	  component: () => import('@/views/user/SendGift')
   },
   {
	  path: '/photoList',//遇见->用户主页->相册
	  name: 'photoList',
	  component: () => import('@/views/user/PhotoList')
   },
   {
	  path: '/mine',//我的
	  name: 'mine',
	  component: () => import('@/views/tab/Mine')
   },
   {
	  path: '/setting',//我的->设置
	  name: 'setting',
	  component: () => import('@/views/setting/Setting')
   },
   {
	  path: '/languageSetting',//我的->设置->语言设置
	  name: 'languageSetting',
	  component: () => import('@/views/setting/LanguageSetting')
   },
   {
	  path: '/editUserInfo',//我的->设置->修改资料  
	  name: 'editUserInfo',
	  component: () => import('@/views/setting/EditUserInfo')
   },
   {
	  path: '/addPhoto',//我的->设置->修改资料->上传头像  
	  name: 'addPhoto',
	  component: () => import('@/views/setting/AddPhoto')
   },
   {
	  path: '/updPassword',//我的->设置->修改密码
	  name: 'updPassword',
	  component: () => import('@/views/updPassword')
   },
   {
	  path: '/userInfo',//我的->我的主页
	  name: 'userInfo',
	  component: () => import('@/views/user/UserInfo')
   },
   {
	  path: '/emojiList',//我的->表情商店
	  name: 'emojiList',
	  component: () => import('@/views/user/EmojiList')
   },
   {
	  path: '/visitList',//我的->我喜欢的、喜欢我的、互相喜欢
	  name: 'visitList',
	  component: () => import('@/views/user/VisitList')
   },
   {
	  path: '/seeList',//我的->谁看过我
	  name: 'seeList',
	  component: () => import('@/views/user/SeeList')
   },
   {
	  path: '/gift',//我的->礼物盒子、送出礼物
	  name: 'gift',
	  component: () => import('@/views/user/Gift')
   },
   {
	  path: '/upgrade',//我的->我要升级
	  name: 'upgrade',
	  component: () => import('@/views/user/Upgrade')
   },
   {
	  path: '/paymoney',//我的->我要充值
	  name: 'paymoney',
	  component: () => import('@/views/user/PayMoney')
   }
   
]

const router = new VueRouter({
	// mode: 'history', // 去掉url中的# 需要路由模式改为history
	base: 'app', // 这个配置也很重要，否则会出现页面空白情况
	scrollBehavior: () => ({ y: 0 }),
	routes
})

//判断登录
router.beforeEach((to, from, next) => {
    // to.path === '/'
	// next();
	if(to.path === '/forgetPass' || to.path === '/index' || to.path === '/login' || to.path === '/register'){
		
		next();
    }else{ 
		var user = getUser(true);
        if(!user){ //判断是否登录,跳转index界面
            next({
                path: '/index'
            })
        }else{
			next();
		}
	}
  })


export default router
